<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">

<html><head><title>Db_mysql - ezRPG</title><link rel="stylesheet" type="text/css" href="../../styles/main.css"><script language=JavaScript src="../../javascript/main.js"></script><script language=JavaScript src="../../javascript/searchdata.js"></script></head><body class="ContentPage" onLoad="NDOnLoad()"><script language=JavaScript><!--
if (browserType) {document.write("<div class=" + browserType + ">");if (browserVer) {document.write("<div class=" + browserVer + ">"); }}// --></script>

<!--  Generated by Natural Docs, version 1.4 -->
<!--  http://www.naturaldocs.org  -->

<!-- saved from url=(0026)http://www.naturaldocs.org -->




<div id=Content><div class="CClass"><div class=CTopic id=MainTopic><h1 class=CTitle><a name="Db_mysql"></a>Db_mysql</h1><div class=CBody><p>Database abstraction class for MySQL.</p><h4 class=CHeading>See Also</h4><ul><li><a href="class-dbfactory-php.html#DbFactory" class=LClass id=link20 onMouseOver="ShowTip(event, 'tt17', 'link20')" onMouseOut="HideTip('tt17')">DbFactory</a></li><li><a href="exception-db-php.html#DbException" class=LClass id=link21 onMouseOver="ShowTip(event, 'tt18', 'link21')" onMouseOut="HideTip('tt18')">DbException</a></li></ul><!--START_ND_SUMMARY--><div class=Summary><div class=STitle>Summary</div><div class=SBorder><table border=0 cellspacing=0 cellpadding=0 class=STable><tr class="SMain"><td class=SEntry><a href="#Db_mysql" >Db_mysql</a></td><td class=SDescription>Database abstraction class for MySQL.</td></tr><tr class="SGroup SIndent1"><td class=SEntry><a href="#Db_mysql.Variables" >Variables</a></td><td class=SDescription></td></tr><tr class="SVariable SIndent2 SMarked"><td class=SEntry><a href="#Db_mysql.$query_count" id=link1 onMouseOver="ShowTip(event, 'tt1', 'link1')" onMouseOut="HideTip('tt1')">$query_count</a></td><td class=SDescription>Keeps track of number of queries made in this database connection.</td></tr><tr class="SVariable SIndent2"><td class=SEntry><a href="#Db_mysql.$error" id=link2 onMouseOver="ShowTip(event, 'tt2', 'link2')" onMouseOut="HideTip('tt2')">$error</a></td><td class=SDescription>Contains the last SQL error.</td></tr><tr class="SVariable SIndent2 SMarked"><td class=SEntry><a href="#Db_mysql.$query" id=link3 onMouseOver="ShowTip(event, 'tt3', 'link3')" onMouseOut="HideTip('tt3')">$query</a></td><td class=SDescription>Contains the last query executed.</td></tr><tr class="SVariable SIndent2"><td class=SEntry><a href="#Db_mysql.$isConnected" id=link4 onMouseOver="ShowTip(event, 'tt4', 'link4')" onMouseOut="HideTip('tt4')">$isConnected</a></td><td class=SDescription>A boolean showing the status of the database connection.</td></tr><tr class="SVariable SIndent2 SMarked"><td class=SEntry><a href="#Db_mysql.$db" id=link5 onMouseOver="ShowTip(event, 'tt5', 'link5')" onMouseOut="HideTip('tt5')">$db</a></td><td class=SDescription>Contains a MySQL link identifier.</td></tr><tr class="SVariable SIndent2"><td class=SEntry><a href="#Db_mysql.Connection_Details" >Connection Details</a></td><td class=SDescription></td></tr><tr class="SGroup SIndent1"><td class=SEntry><a href="#Db_mysql.Functions" >Functions</a></td><td class=SDescription></td></tr><tr class="SFunction SIndent2 SMarked"><td class=SEntry><a href="#Db_mysql.__construct" id=link6 onMouseOver="ShowTip(event, 'tt6', 'link6')" onMouseOut="HideTip('tt6')">__construct</a></td><td class=SDescription>Saves the connection data for later use. </td></tr><tr class="SFunction SIndent2"><td class=SEntry><a href="#Db_mysql.__destruct" id=link7 onMouseOver="ShowTip(event, 'tt7', 'link7')" onMouseOut="HideTip('tt7')">__destruct</a></td><td class=SDescription>Closes the connection to the MySQL server.</td></tr><tr class="SFunction SIndent2 SMarked"><td class=SEntry><a href="#Db_mysql.execute" id=link8 onMouseOver="ShowTip(event, 'tt8', 'link8')" onMouseOut="HideTip('tt8')">execute</a></td><td class=SDescription>Checks if a connection is made, otherwise first calls <a href="#Db_mysql.connect" class=LFunction id=link9 onMouseOver="ShowTip(event, 'tt9', 'link9')" onMouseOut="HideTip('tt9')">connect</a>. </td></tr><tr class="SFunction SIndent2"><td class=SEntry><a href="#Db_mysql.fetch" id=link10 onMouseOver="ShowTip(event, 'tt10', 'link10')" onMouseOut="HideTip('tt10')">fetch</a></td><td class=SDescription>Fetches the data from the result set and returns it as an object.</td></tr><tr class="SFunction SIndent2 SMarked"><td class=SEntry><a href="#Db_mysql.fetchArray" id=link11 onMouseOver="ShowTip(event, 'tt11', 'link11')" onMouseOut="HideTip('tt11')">fetchArray</a></td><td class=SDescription>Fetches the data from the result set and returns it as an array.</td></tr><tr class="SFunction SIndent2"><td class=SEntry><a href="#Db_mysql.fetchAll" id=link12 onMouseOver="ShowTip(event, 'tt12', 'link12')" onMouseOut="HideTip('tt12')">fetchAll</a></td><td class=SDescription>Fetches all the data from a result set and returns it as an array of results.</td></tr><tr class="SFunction SIndent2 SMarked"><td class=SEntry><a href="#Db_mysql.fetchRow" id=link13 onMouseOver="ShowTip(event, 'tt13', 'link13')" onMouseOut="HideTip('tt13')">fetchRow</a></td><td class=SDescription>Combines <a href="#Db_mysql.execute" class=LFunction id=link14 onMouseOver="ShowTip(event, 'tt8', 'link14')" onMouseOut="HideTip('tt8')">execute</a> and <a href="#Db_mysql.fetch" class=LFunction id=link15 onMouseOver="ShowTip(event, 'tt10', 'link15')" onMouseOut="HideTip('tt10')">fetch</a> to a single function for fetching single rows of data.</td></tr><tr class="SFunction SIndent2"><td class=SEntry><a href="#Db_mysql.numRows" id=link16 onMouseOver="ShowTip(event, 'tt14', 'link16')" onMouseOut="HideTip('tt14')">numRows</a></td><td class=SDescription>Uses mysql_num_rows on a result set to return the number of rows.</td></tr><tr class="SFunction SIndent2 SMarked"><td class=SEntry><a href="#Db_mysql.insert" id=link17 onMouseOver="ShowTip(event, 'tt15', 'link17')" onMouseOut="HideTip('tt15')">insert</a></td><td class=SDescription>Takes an array to generate an INSERT query, then executes it.</td></tr><tr class="SFunction SIndent2"><td class=SEntry><a href="#Db_mysql.affected" id=link18 onMouseOver="ShowTip(event, 'tt16', 'link18')" onMouseOut="HideTip('tt16')">affected</a></td><td class=SDescription>Returns the number of affected rows from the last query executed.</td></tr><tr class="SFunction SIndent2 SMarked"><td class=SEntry><a href="#Db_mysql.connect" id=link19 onMouseOver="ShowTip(event, 'tt9', 'link19')" onMouseOut="HideTip('tt9')">connect</a></td><td class=SDescription>Connects to a MySQL server and selects a database.</td></tr></table></div></div><!--END_ND_SUMMARY--></div></div></div>

<div class="CGroup"><div class=CTopic><h3 class=CTitle><a name="Db_mysql.Variables"></a>Variables</h3></div></div>

<div class="CVariable"><div class=CTopic><h3 class=CTitle><a name="Db_mysql.$query_count"></a>$query_count</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class=Prototype><tr><td>public $query_count</td></tr></table></blockquote><p>Keeps track of number of queries made in this database connection.</p></div></div></div>

<div class="CVariable"><div class=CTopic><h3 class=CTitle><a name="Db_mysql.$error"></a>$error</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class=Prototype><tr><td>public $error</td></tr></table></blockquote><p>Contains the last SQL error.</p></div></div></div>

<div class="CVariable"><div class=CTopic><h3 class=CTitle><a name="Db_mysql.$query"></a>$query</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class=Prototype><tr><td>public $query</td></tr></table></blockquote><p>Contains the last query executed.</p></div></div></div>

<div class="CVariable"><div class=CTopic><h3 class=CTitle><a name="Db_mysql.$isConnected"></a>$isConnected</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class=Prototype><tr><td>public $isConnected</td></tr></table></blockquote><p>A boolean showing the status of the database connection.</p></div></div></div>

<div class="CVariable"><div class=CTopic><h3 class=CTitle><a name="Db_mysql.$db"></a>$db</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class=Prototype><tr><td>protected $db</td></tr></table></blockquote><p>Contains a MySQL link identifier.</p></div></div></div>

<div class="CVariable"><div class=CTopic><h3 class=CTitle><a name="Db_mysql.Connection_Details"></a>Connection Details</h3><div class=CBody><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry><a name="$host"></a>$host</td><td class=CDLDescription>Host name of database server.</td></tr><tr><td class=CDLEntry><a name="$dbname"></a>$dbname</td><td class=CDLDescription>Name of the database.</td></tr><tr><td class=CDLEntry><a name="$username"></a>$username</td><td class=CDLDescription>Username to connect with.</td></tr><tr><td class=CDLEntry><a name="$password"></a>$password</td><td class=CDLDescription>Password to connect with.</td></tr></table></div></div></div>

<div class="CGroup"><div class=CTopic><h3 class=CTitle><a name="Db_mysql.Functions"></a>Functions</h3></div></div>

<div class="CFunction"><div class=CTopic><h3 class=CTitle><a name="Db_mysql.__construct"></a>__construct</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class=Prototype><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class=PBeforeParameters nowrap>public function __construct(</td><td class=PParameter nowrap>$host</td><td class=PDefaultValuePrefix>&nbsp;=&nbsp;</td><td class=PDefaultValue width=100%>'localhost',</td></tr><tr><td></td><td class=PParameter nowrap>$username</td><td class=PDefaultValuePrefix>&nbsp;=&nbsp;</td><td class=PDefaultValue width=100%>'root',</td></tr><tr><td></td><td class=PParameter nowrap>$password</td><td class=PDefaultValuePrefix>&nbsp;=&nbsp;</td><td class=PDefaultValue width=100%>'',</td></tr><tr><td></td><td class=PParameter nowrap>$dbname</td><td class=PDefaultValuePrefix>&nbsp;=&nbsp;</td><td class=PDefaultValue width=100%>''</td><td class=PAfterParameters nowrap>)</td></tr></table></td></tr></table></blockquote><p>Saves the connection data for later use.&nbsp; Does not start a connection yet.</p><h4 class=CHeading>Parameters</h4><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>$host</td><td class=CDLDescription>Database server</td></tr><tr><td class=CDLEntry>$username</td><td class=CDLDescription>Username to login with</td></tr><tr><td class=CDLEntry>$password</td><td class=CDLDescription>Password to login with</td></tr><tr><td class=CDLEntry>$dbname</td><td class=CDLDescription>Name of database</td></tr></table></div></div></div>

<div class="CFunction"><div class=CTopic><h3 class=CTitle><a name="Db_mysql.__destruct"></a>__destruct</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class=Prototype><tr><td>public function __destruct()</td></tr></table></blockquote><p>Closes the connection to the MySQL server.</p></div></div></div>

<div class="CFunction"><div class=CTopic><h3 class=CTitle><a name="Db_mysql.execute"></a>execute</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class=Prototype><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class=PBeforeParameters nowrap>public function execute(</td><td class=PParameter nowrap>$query,</td><td class=PDefaultValuePrefix>&nbsp;&nbsp;</td></tr><tr><td></td><td class=PParameter nowrap>$params</td><td class=PDefaultValuePrefix>&nbsp;=&nbsp;</td><td class=PAfterParameters nowrap>)</td></tr></table></td></tr></table></blockquote><p>Checks if a connection is made, otherwise first calls <a href="#Db_mysql.connect" class=LFunction id=link22 onMouseOver="ShowTip(event, 'tt9', 'link22')" onMouseOut="HideTip('tt9')">connect</a>.&nbsp; Executes a query and returns the result (a resource or boolean).</p><h4 class=CHeading>Parameters</h4><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>$query</td><td class=CDLDescription>A string with the SQL query to execute.</td></tr><tr><td class=CDLEntry>$params</td><td class=CDLDescription>An optional array of parameters to use with parameter binding.</td></tr></table><h4 class=CHeading>Returns</h4><p>The result of the SQL query.&nbsp; Either a resource or a boolean.&nbsp; On a failed query, it returns false.&nbsp; On an SQL error, it throws a <a href="exception-db-php.html#DbException" class=LClass id=link23 onMouseOver="ShowTip(event, 'tt18', 'link23')" onMouseOut="HideTip('tt18')">DbException</a> with the MySQL error.</p><h4 class=CHeading>Example Usage</h4><blockquote><pre>$query = $db-&gt;execute('SELECT username FROM &lt;ezrpg&gt;players WHERE id=?', array($player-&gt;id));</pre></blockquote><blockquote><pre>$query = $db-&gt;execute('SELECT COUNT(id) AS count FROM &lt;ezrpg&gt;players');</pre></blockquote><h4 class=CHeading>See Also</h4><ul><li><a href="#Db_mysql.connect" class=LFunction id=link24 onMouseOver="ShowTip(event, 'tt9', 'link24')" onMouseOut="HideTip('tt9')">connect</a></li></ul></div></div></div>

<div class="CFunction"><div class=CTopic><h3 class=CTitle><a name="Db_mysql.fetch"></a>fetch</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class=Prototype><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class=PBeforeParameters nowrap>public function fetch(</td><td class=PParameterPrefix nowrap>&amp;</td><td class=PParameter nowrap>$result</td><td class=PAfterParameters nowrap>)</td></tr></table></td></tr></table></blockquote><p>Fetches the data from the result set and returns it as an object.</p><h4 class=CHeading>Parameters</h4><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>$result</td><td class=CDLDescription>A result set from an SQL query.</td></tr></table><h4 class=CHeading>Returns</h4><p>The results from the query in an array.</p><h4 class=CHeading>Example Usage</h4><blockquote><pre>$query = $db-&gt;execute('SELECT COUNT(id) AS count FROM &lt;ezrpg&gt;players');
$result = $db-&gt;fetch($query);
echo $result-&gt;count;</pre></blockquote><h4 class=CHeading>See Also</h4><ul><li><a href="#Db_mysql.execute" class=LFunction id=link25 onMouseOver="ShowTip(event, 'tt8', 'link25')" onMouseOut="HideTip('tt8')">execute</a></li><li><a href="#Db_mysql.fetchRow" class=LFunction id=link26 onMouseOver="ShowTip(event, 'tt13', 'link26')" onMouseOut="HideTip('tt13')">fetchRow</a></li></ul></div></div></div>

<div class="CFunction"><div class=CTopic><h3 class=CTitle><a name="Db_mysql.fetchArray"></a>fetchArray</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class=Prototype><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class=PBeforeParameters nowrap>public function fetchArray(</td><td class=PParameterPrefix nowrap>&amp;</td><td class=PParameter nowrap>$result</td><td class=PAfterParameters nowrap>)</td></tr></table></td></tr></table></blockquote><p>Fetches the data from the result set and returns it as an array.</p><h4 class=CHeading>Parameters</h4><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>$result</td><td class=CDLDescription>A result set from an SQL query.</td></tr></table><h4 class=CHeading>Returns</h4><p>An array with the query results.</p><h4 class=CHeading>Example Usage</h4><blockquote><pre>$query = $db-&gt;execute('SELECT COUNT(`id`) AS `count` FROM `&lt;ezrpg&gt;players`');
$result = $db-&gt;fetchArray($query);
echo $result['count'];</pre></blockquote><h4 class=CHeading>See Also</h4><ul><li><a href="#Db_mysql.execute" class=LFunction id=link27 onMouseOver="ShowTip(event, 'tt8', 'link27')" onMouseOut="HideTip('tt8')">execute</a></li><li><a href="#Db_mysql.fetch" class=LFunction id=link28 onMouseOver="ShowTip(event, 'tt10', 'link28')" onMouseOut="HideTip('tt10')">fetch</a></li></ul></div></div></div>

<div class="CFunction"><div class=CTopic><h3 class=CTitle><a name="Db_mysql.fetchAll"></a>fetchAll</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class=Prototype><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class=PBeforeParameters nowrap>public function fetchAll(</td><td class=PParameterPrefix nowrap>&amp;</td><td class=PParameter nowrap>$result,</td><td class=PDefaultValuePrefix>&nbsp;&nbsp;</td><td class=PDefaultValue width=100%></td></tr><tr><td></td><td class=PParameterPrefix nowrap></td><td class=PParameter nowrap>$return_array</td><td class=PDefaultValuePrefix>&nbsp;=&nbsp;</td><td class=PDefaultValue width=100%> false</td><td class=PAfterParameters nowrap>)</td></tr></table></td></tr></table></blockquote><p>Fetches all the data from a result set and returns it as an array of results.</p><h4 class=CHeading>Parameters</h4><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>$result</td><td class=CDLDescription>A result set from an SQL query.</td></tr><tr><td class=CDLEntry>$return_array</td><td class=CDLDescription>Boolean to return the result as arrays or objects.</td></tr></table><h4 class=CHeading>Returns</h4><p>An array of arrays/objects from query results.&nbsp; On a failed query, returns false.</p><h4 class=CHeading>Example Usage</h4><blockquote><pre>$query = $db-&gt;execute('SELECT `id` FROM `&lt;ezrpg&gt;players`');
$results = $db-&gt;fetchAll($query);
foreach ($results as $row)
  echo $row-&gt;id;</pre></blockquote><h4 class=CHeading>See Also</h4><ul><li><a href="#Db_mysql.execute" class=LFunction id=link29 onMouseOver="ShowTip(event, 'tt8', 'link29')" onMouseOut="HideTip('tt8')">execute</a></li><li><a href="#Db_mysql.fetch" class=LFunction id=link30 onMouseOver="ShowTip(event, 'tt10', 'link30')" onMouseOut="HideTip('tt10')">fetch</a></li><li><a href="#Db_mysql.fetchArray" class=LFunction id=link31 onMouseOver="ShowTip(event, 'tt11', 'link31')" onMouseOut="HideTip('tt11')">fetchArray</a></li></ul></div></div></div>

<div class="CFunction"><div class=CTopic><h3 class=CTitle><a name="Db_mysql.fetchRow"></a>fetchRow</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class=Prototype><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class=PBeforeParameters nowrap>public function fetchRow(</td><td class=PParameter nowrap>$query,</td><td class=PDefaultValuePrefix>&nbsp;&nbsp;</td></tr><tr><td></td><td class=PParameter nowrap>$params</td><td class=PDefaultValuePrefix>&nbsp;=&nbsp;</td><td class=PAfterParameters nowrap>)</td></tr></table></td></tr></table></blockquote><p>Combines <a href="#Db_mysql.execute" class=LFunction id=link32 onMouseOver="ShowTip(event, 'tt8', 'link32')" onMouseOut="HideTip('tt8')">execute</a> and <a href="#Db_mysql.fetch" class=LFunction id=link33 onMouseOver="ShowTip(event, 'tt10', 'link33')" onMouseOut="HideTip('tt10')">fetch</a> to a single function for fetching single rows of data.</p><p>Equivalent to using mysql_fetch_object(mysql_query($query)).</p><p>After the row is fetched, all memory associated with the result is freed with mysql_free_result().</p><h4 class=CHeading>Parameters</h4><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>$query</td><td class=CDLDescription>A string with the SQL query to execute.</td></tr><tr><td class=CDLEntry>$params</td><td class=CDLDescription>An optional array of parameters to use with parameter binding.</td></tr></table><h4 class=CHeading>Returns</h4><p>The results from the query in an array.</p><h4 class=CHeading>Example Usage</h4><blockquote><pre>$result = $db-&gt;fetchRow('SELECT COUNT(id) AS count FROM &lt;ezrpg&gt;players');
echo $result-&gt;count;</pre></blockquote><h4 class=CHeading>See Also</h4><ul><li><a href="#Db_mysql.execute" class=LFunction id=link34 onMouseOver="ShowTip(event, 'tt8', 'link34')" onMouseOut="HideTip('tt8')">execute</a></li><li><a href="#Db_mysql.fetch" class=LFunction id=link35 onMouseOver="ShowTip(event, 'tt10', 'link35')" onMouseOut="HideTip('tt10')">fetch</a></li></ul></div></div></div>

<div class="CFunction"><div class=CTopic><h3 class=CTitle><a name="Db_mysql.numRows"></a>numRows</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class=Prototype><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class=PBeforeParameters nowrap>public function numRows(</td><td class=PParameterPrefix nowrap>&amp;</td><td class=PParameter nowrap>$result</td><td class=PAfterParameters nowrap>)</td></tr></table></td></tr></table></blockquote><p>Uses mysql_num_rows on a result set to return the number of rows.</p><h4 class=CHeading>Parameters</h4><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>$result</td><td class=CDLDescription>A result set from an SQL query.</td></tr></table><h4 class=CHeading>Returns</h4><p>The number of rows in the result set.</p></div></div></div>

<div class="CFunction"><div class=CTopic><h3 class=CTitle><a name="Db_mysql.insert"></a>insert</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class=Prototype><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class=PBeforeParameters nowrap>public function insert(</td><td class=PParameter nowrap>$table,</td></tr><tr><td></td><td class=PParameter nowrap>$data</td><td class=PAfterParameters nowrap>)</td></tr></table></td></tr></table></blockquote><p>Takes an array to generate an INSERT query, then executes it.</p><h4 class=CHeading>Parameters</h4><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>$table</td><td class=CDLDescription>Name of the table to insert into.</td></tr><tr><td class=CDLEntry>$data</td><td class=CDLDescription>An array with keys being column names.</td></tr></table><h4 class=CHeading>Returns</h4><p>ID generated by the AUTO_INCREMENT column.</p><h4 class=CHeading>Example Usage</h4><blockquote><pre>$insert = Array();
$insert['username'] = 'Andy';
$insert['password'] = 'a9629b9ff4f0637362a0954224e1cd5792effb62';
$insert['email'] = 'andy@ezrpgproject.com';
$insert['registered'] = time();
$new_player = $db-&gt;insert('&lt;ezrpg&gt;players', $insert);</pre></blockquote><h4 class=CHeading>See Also</h4><ul><li><a href="#Db_mysql.execute" class=LFunction id=link36 onMouseOver="ShowTip(event, 'tt8', 'link36')" onMouseOut="HideTip('tt8')">execute</a></li></ul></div></div></div>

<div class="CFunction"><div class=CTopic><h3 class=CTitle><a name="Db_mysql.affected"></a>affected</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class=Prototype><tr><td>public function affected()</td></tr></table></blockquote><p>Returns the number of affected rows from the last query executed.</p><h4 class=CHeading>Returns</h4><p>An integer representing the number of affected rows, or -1 if the query failed.</p></div></div></div>

<div class="CFunction"><div class=CTopic><h3 class=CTitle><a name="Db_mysql.connect"></a>connect</h3><div class=CBody><blockquote><table border=0 cellspacing=0 cellpadding=0 class=Prototype><tr><td>protected function connect()</td></tr></table></blockquote><p>Connects to a MySQL server and selects a database.</p><h4 class=CHeading>Parameters</h4><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>$host</td><td class=CDLDescription>Database server</td></tr><tr><td class=CDLEntry>$username</td><td class=CDLDescription>Username to login with</td></tr><tr><td class=CDLEntry>$password</td><td class=CDLDescription>Password to login with</td></tr><tr><td class=CDLEntry>$dbname</td><td class=CDLDescription>Name of database</td></tr></table><h4 class=CHeading>Returns</h4><p>True if there were no errors.</p><p>Throws a <a href="exception-db-php.html#DbException" class=LClass id=link37 onMouseOver="ShowTip(event, 'tt18', 'link37')" onMouseOut="HideTip('tt18')">DbException</a> if there was a connection problem.</p></div></div></div>

</div><!--Content-->


<div id=Footer>Copyright &copy; 2009 ezRPG Project&nbsp; &middot;&nbsp; Updated June 26th, 2010&nbsp; &middot;&nbsp; <a href="http://www.naturaldocs.org">Generated by Natural Docs</a></div><!--Footer-->


<div id=Menu><div class=MTitle>ezRPG<div class=MSubTitle>Documentation</div></div><div class=MEntry><div class=MFile><a href="../config-php.html">Config</a></div></div><div class=MEntry><div class=MFile><a href="../modules/example-php.html">Module_Example</a></div></div><div class=MEntry><div class=MFile><a href="../modules/skeleton-php.html">Module_Skeleton</a></div></div><div class=MEntry><div class=MGroup><a href="javascript:ToggleMenu('MGroupContent1')">Lib</a><div class=MGroupContent id=MGroupContent1><div class=MEntry><div class=MFile><a href="const-errors-php.html">Error Codes</a></div></div><div class=MEntry><div class=MFile><a href="func-log-php.html">Log Functions</a></div></div><div class=MEntry><div class=MFile><a href="func-player-php.html">Player Functions</a></div></div><div class=MEntry><div class=MFile><a href="func-rand-php.html">Random Functions</a></div></div><div class=MEntry><div class=MFile><a href="func-text-php.html">Text Functions</a></div></div><div class=MEntry><div class=MFile><a href="func-validate-php.html">Validation functions</a></div></div></div></div></div><div class=MEntry><div class=MGroup><a href="javascript:ToggleMenu('MGroupContent2')">Classes</a><div class=MGroupContent id=MGroupContent2><div class=MEntry><div class=MFile><a href="class-base_module-php.html">Base_Module</a></div></div><div class=MEntry><div class=MFile><a href="class-dbfactory-php.html">DbFactory</a></div></div><div class=MEntry><div class=MFile><a href="class-hooks-php.html">Hooks</a></div></div><div class=MEntry><div class=MFile><a href="class-imagebar-php.html">ImageBar</a></div></div><div class=MEntry><div class=MFile><a href="class-modulefactory-php.html">ModuleFactory</a></div></div></div></div></div><div class=MEntry><div class=MGroup><a href="javascript:ToggleMenu('MGroupContent3')">Modules</a><div class=MGroupContent id=MGroupContent3><div class=MEntry><div class=MFile><a href="../modules/AccountSettings/index-php.html">AccountSettings</a></div></div><div class=MEntry><div class=MFile><a href="../modules/City/index-php.html">City</a></div></div><div class=MEntry><div class=MFile><a href="../modules/EventLog/index-php.html">EventLog</a></div></div><div class=MEntry><div class=MFile><a href="../modules/Index/index-php.html">Index</a></div></div><div class=MEntry><div class=MFile><a href="../modules/Login/index-php.html">Login</a></div></div><div class=MEntry><div class=MFile><a href="../modules/Logout/index-php.html">Logout</a></div></div><div class=MEntry><div class=MFile><a href="../modules/Members/index-php.html">Members</a></div></div><div class=MEntry><div class=MFile><a href="../modules/Register/index-php.html">Register</a></div></div><div class=MEntry><div class=MFile><a href="../modules/StatPoints/index-php.html">StatPoints</a></div></div></div></div></div><div class=MEntry><div class=MGroup><a href="javascript:ToggleMenu('MGroupContent4')">Admin Modules</a><div class=MGroupContent id=MGroupContent4><div class=MEntry><div class=MFile><a href="../admin/Index/index-php.html">Admin_Index</a></div></div><div class=MEntry><div class=MFile><a href="../admin/Members/index-php.html">Admin_Members</a></div></div></div></div></div><div class=MEntry><div class=MGroup><a href="javascript:ToggleMenu('MGroupContent5')">Database Drivers</a><div class=MGroupContent id=MGroupContent5><div class=MEntry><div class=MFile id=MSelected>Db_mysql</div></div></div></div></div><div class=MEntry><div class=MGroup><a href="javascript:ToggleMenu('MGroupContent6')">Exceptions</a><div class=MGroupContent id=MGroupContent6><div class=MEntry><div class=MFile><a href="exception-db-php.html">DbException</a></div></div><div class=MEntry><div class=MFile><a href="exception-file-php.html">FileException</a></div></div></div></div></div><div class=MEntry><div class=MGroup><a href="javascript:ToggleMenu('MGroupContent7')">Index</a><div class=MGroupContent id=MGroupContent7><div class=MEntry><div class=MIndex><a href="../../index/General.html">Everything</a></div></div><div class=MEntry><div class=MIndex><a href="../../index/Classes.html">Classes</a></div></div><div class=MEntry><div class=MIndex><a href="../../index/Functions.html">Functions</a></div></div><div class=MEntry><div class=MIndex><a href="../../index/Variables.html">Variables</a></div></div><div class=MEntry><div class=MIndex><a href="../../index/Constants.html">Constants</a></div></div></div></div></div><div class=MEntry><div class=MFile><a href="../install-php.html">Install</a></div></div><div class=MEntry><div class=MLink><a href="http://www.ezrpgproject.com/">ezRPG Project</a></div></div><script type="text/javascript"><!--
var searchPanel = new SearchPanel("searchPanel", "HTML", "../../search");
--></script><div id=MSearchPanel class=MSearchPanelInactive><input type=text id=MSearchField value=Search onFocus="searchPanel.OnSearchFieldFocus(true)" onBlur="searchPanel.OnSearchFieldFocus(false)" onKeyUp="searchPanel.OnSearchFieldChange()"><select id=MSearchType onFocus="searchPanel.OnSearchTypeFocus(true)" onBlur="searchPanel.OnSearchTypeFocus(false)" onChange="searchPanel.OnSearchTypeChange()"><option  id=MSearchEverything selected value="General">Everything</option><option value="Classes">Classes</option><option value="Constants">Constants</option><option value="Functions">Functions</option><option value="Variables">Variables</option></select></div><script language=JavaScript><!--
HideAllBut([5, 6, 4, 7], 8);// --></script></div><!--Menu-->



<!--START_ND_TOOLTIPS-->
<div class=CToolTip id="tt1"><div class=CVariable><blockquote><table border=0 cellspacing=0 cellpadding=0 class=Prototype><tr><td>public $query_count</td></tr></table></blockquote>Keeps track of number of queries made in this database connection.</div></div><div class=CToolTip id="tt2"><div class=CVariable><blockquote><table border=0 cellspacing=0 cellpadding=0 class=Prototype><tr><td>public $error</td></tr></table></blockquote>Contains the last SQL error.</div></div><div class=CToolTip id="tt3"><div class=CVariable><blockquote><table border=0 cellspacing=0 cellpadding=0 class=Prototype><tr><td>public $query</td></tr></table></blockquote>Contains the last query executed.</div></div><div class=CToolTip id="tt4"><div class=CVariable><blockquote><table border=0 cellspacing=0 cellpadding=0 class=Prototype><tr><td>public $isConnected</td></tr></table></blockquote>A boolean showing the status of the database connection.</div></div><div class=CToolTip id="tt5"><div class=CVariable><blockquote><table border=0 cellspacing=0 cellpadding=0 class=Prototype><tr><td>protected $db</td></tr></table></blockquote>Contains a MySQL link identifier.</div></div><div class=CToolTip id="tt6"><div class=CFunction><blockquote><table border=0 cellspacing=0 cellpadding=0 class=Prototype><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class=PBeforeParameters nowrap>public function __construct(</td><td class=PParameter nowrap>$host</td><td class=PDefaultValuePrefix>&nbsp;=&nbsp;</td><td class=PDefaultValue width=100%>'localhost',</td></tr><tr><td></td><td class=PParameter nowrap>$username</td><td class=PDefaultValuePrefix>&nbsp;=&nbsp;</td><td class=PDefaultValue width=100%>'root',</td></tr><tr><td></td><td class=PParameter nowrap>$password</td><td class=PDefaultValuePrefix>&nbsp;=&nbsp;</td><td class=PDefaultValue width=100%>'',</td></tr><tr><td></td><td class=PParameter nowrap>$dbname</td><td class=PDefaultValuePrefix>&nbsp;=&nbsp;</td><td class=PDefaultValue width=100%>''</td><td class=PAfterParameters nowrap>)</td></tr></table></td></tr></table></blockquote>Saves the connection data for later use. </div></div><div class=CToolTip id="tt7"><div class=CFunction><blockquote><table border=0 cellspacing=0 cellpadding=0 class=Prototype><tr><td>public function __destruct()</td></tr></table></blockquote>Closes the connection to the MySQL server.</div></div><div class=CToolTip id="tt8"><div class=CFunction><blockquote><table border=0 cellspacing=0 cellpadding=0 class=Prototype><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class=PBeforeParameters nowrap>public function execute(</td><td class=PParameter nowrap>$query,</td><td class=PDefaultValuePrefix>&nbsp;&nbsp;</td></tr><tr><td></td><td class=PParameter nowrap>$params</td><td class=PDefaultValuePrefix>&nbsp;=&nbsp;</td><td class=PAfterParameters nowrap>)</td></tr></table></td></tr></table></blockquote>Checks if a connection is made, otherwise first calls connect. </div></div><div class=CToolTip id="tt9"><div class=CFunction><blockquote><table border=0 cellspacing=0 cellpadding=0 class=Prototype><tr><td>protected function connect()</td></tr></table></blockquote>Connects to a MySQL server and selects a database.</div></div><div class=CToolTip id="tt10"><div class=CFunction><blockquote><table border=0 cellspacing=0 cellpadding=0 class=Prototype><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class=PBeforeParameters nowrap>public function fetch(</td><td class=PParameterPrefix nowrap>&amp;</td><td class=PParameter nowrap>$result</td><td class=PAfterParameters nowrap>)</td></tr></table></td></tr></table></blockquote>Fetches the data from the result set and returns it as an object.</div></div><div class=CToolTip id="tt11"><div class=CFunction><blockquote><table border=0 cellspacing=0 cellpadding=0 class=Prototype><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class=PBeforeParameters nowrap>public function fetchArray(</td><td class=PParameterPrefix nowrap>&amp;</td><td class=PParameter nowrap>$result</td><td class=PAfterParameters nowrap>)</td></tr></table></td></tr></table></blockquote>Fetches the data from the result set and returns it as an array.</div></div><div class=CToolTip id="tt12"><div class=CFunction><blockquote><table border=0 cellspacing=0 cellpadding=0 class=Prototype><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class=PBeforeParameters nowrap>public function fetchAll(</td><td class=PParameterPrefix nowrap>&amp;</td><td class=PParameter nowrap>$result,</td><td class=PDefaultValuePrefix>&nbsp;&nbsp;</td><td class=PDefaultValue width=100%></td></tr><tr><td></td><td class=PParameterPrefix nowrap></td><td class=PParameter nowrap>$return_array</td><td class=PDefaultValuePrefix>&nbsp;=&nbsp;</td><td class=PDefaultValue width=100%> false</td><td class=PAfterParameters nowrap>)</td></tr></table></td></tr></table></blockquote>Fetches all the data from a result set and returns it as an array of results.</div></div><div class=CToolTip id="tt13"><div class=CFunction><blockquote><table border=0 cellspacing=0 cellpadding=0 class=Prototype><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class=PBeforeParameters nowrap>public function fetchRow(</td><td class=PParameter nowrap>$query,</td><td class=PDefaultValuePrefix>&nbsp;&nbsp;</td></tr><tr><td></td><td class=PParameter nowrap>$params</td><td class=PDefaultValuePrefix>&nbsp;=&nbsp;</td><td class=PAfterParameters nowrap>)</td></tr></table></td></tr></table></blockquote>Combines execute and fetch to a single function for fetching single rows of data.</div></div><div class=CToolTip id="tt14"><div class=CFunction><blockquote><table border=0 cellspacing=0 cellpadding=0 class=Prototype><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class=PBeforeParameters nowrap>public function numRows(</td><td class=PParameterPrefix nowrap>&amp;</td><td class=PParameter nowrap>$result</td><td class=PAfterParameters nowrap>)</td></tr></table></td></tr></table></blockquote>Uses mysql_num_rows on a result set to return the number of rows.</div></div><div class=CToolTip id="tt15"><div class=CFunction><blockquote><table border=0 cellspacing=0 cellpadding=0 class=Prototype><tr><td><table border=0 cellspacing=0 cellpadding=0><tr><td class=PBeforeParameters nowrap>public function insert(</td><td class=PParameter nowrap>$table,</td></tr><tr><td></td><td class=PParameter nowrap>$data</td><td class=PAfterParameters nowrap>)</td></tr></table></td></tr></table></blockquote>Takes an array to generate an INSERT query, then executes it.</div></div><div class=CToolTip id="tt16"><div class=CFunction><blockquote><table border=0 cellspacing=0 cellpadding=0 class=Prototype><tr><td>public function affected()</td></tr></table></blockquote>Returns the number of affected rows from the last query executed.</div></div><div class=CToolTip id="tt17"><div class=CClass>Factory class for database drivers.</div></div><div class=CToolTip id="tt18"><div class=CClass>Extends Exception class to specify a database error.</div></div><!--END_ND_TOOLTIPS-->




<div id=MSearchResultsWindow><iframe src="" frameborder=0 name=MSearchResults id=MSearchResults></iframe><a href="javascript:searchPanel.CloseResultsWindow()" id=MSearchResultsWindowClose>Close</a></div>


<script language=JavaScript><!--
if (browserType) {if (browserVer) {document.write("</div>"); }document.write("</div>");}// --></script></body></html>